﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace DB.Models;

public partial class QiAuthBaseContext : DbContext
{
    public QiAuthBaseContext()
    {
    }

    public QiAuthBaseContext(DbContextOptions<QiAuthBaseContext> options)
        : base(options)
    {
    }

    public virtual DbSet<Department> Departments { get; set; }

    public virtual DbSet<Log> Logs { get; set; }

    public virtual DbSet<Page> Pages { get; set; }

    public virtual DbSet<PageWithControl> PageWithControls { get; set; }

    public virtual DbSet<PageWithMenu> PageWithMenus { get; set; }

    public virtual DbSet<RegistUser> RegistUsers { get; set; }

    public virtual DbSet<Role> Roles { get; set; }

    public virtual DbSet<RoleComparePageControl> RoleComparePageControls { get; set; }

    public virtual DbSet<ThirdPartyEntrance> ThirdPartyEntrances { get; set; }

    public virtual DbSet<UserDetail> UserDetails { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=QiAuthBase;Persist Security Info=True;User ID=qi;Password=123456;Encrypt=false;");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Department>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__Departme__3214EC07C441F49C");

            entity.ToTable("Department");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Description)
                .HasMaxLength(400)
                .IsUnicode(false);
            entity.Property(e => e.Name)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.ParentId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.Path)
                .HasMaxLength(500)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<Log>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__Log__3214EC07BB9B9E09");

            entity.ToTable("Log");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Key)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.RegistUserId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.Value)
                .HasMaxLength(400)
                .IsUnicode(false);

            entity.HasOne(d => d.RegistUser).WithMany(p => p.Logs)
                .HasForeignKey(d => d.RegistUserId)
                .HasConstraintName("FK__Log__RegistUserI__04AFB25B");
        });

        modelBuilder.Entity<Page>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__Page__3214EC074CA8E7CF");

            entity.ToTable("Page");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Description)
                .HasMaxLength(400)
                .IsUnicode(false);
            entity.Property(e => e.Name)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.Path)
                .HasMaxLength(400)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<PageWithControl>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__PageWith__3214EC07153B69AB");

            entity.ToTable("PageWithControl");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Description)
                .HasMaxLength(400)
                .IsUnicode(false);
            entity.Property(e => e.Name)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.PageId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");

            entity.HasOne(d => d.Page).WithMany(p => p.PageWithControls)
                .HasForeignKey(d => d.PageId)
                .HasConstraintName("FK__PageWithC__PageI__6DCC4D03");
        });

        modelBuilder.Entity<PageWithMenu>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__PageWith__3214EC0723852FB4");

            entity.ToTable("PageWithMenu");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Name)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.PageId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.ParentId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");

            entity.HasOne(d => d.Page).WithMany(p => p.PageWithMenus)
                .HasForeignKey(d => d.PageId)
                .HasConstraintName("FK__PageWithM__PageI__70A8B9AE");
        });

        modelBuilder.Entity<RegistUser>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__RegistUs__3214EC0701CF647A");

            entity.ToTable("RegistUser");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.DepartmentId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.LoginName)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.LoginPassword)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.RoleId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");

            entity.HasOne(d => d.Department).WithMany(p => p.RegistUsers)
                .HasForeignKey(d => d.DepartmentId)
                .HasConstraintName("FK__RegistUse__Depar__7C1A6C5A");

            entity.HasOne(d => d.Role).WithMany(p => p.RegistUsers)
                .HasForeignKey(d => d.RoleId)
                .HasConstraintName("FK__RegistUse__RoleI__7B264821");
        });

        modelBuilder.Entity<Role>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__Role__3214EC071D4A8A2C");

            entity.ToTable("Role");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Description)
                .HasMaxLength(400)
                .IsUnicode(false);
            entity.Property(e => e.Name)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<RoleComparePageControl>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__RoleComp__3214EC079D46A7ED");

            entity.ToTable("RoleComparePageControl");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.PageWithControlId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.RoleId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");

            entity.HasOne(d => d.PageWithControl).WithMany(p => p.RoleComparePageControls)
                .HasForeignKey(d => d.PageWithControlId)
                .HasConstraintName("FK__RoleCompa__PageW__76619304");

            entity.HasOne(d => d.Role).WithMany(p => p.RoleComparePageControls)
                .HasForeignKey(d => d.RoleId)
                .HasConstraintName("FK__RoleCompa__RoleI__756D6ECB");
        });

        modelBuilder.Entity<ThirdPartyEntrance>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__ThirdPar__3214EC07057F85D4");

            entity.ToTable("ThirdPartyEntrance");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.BackValue)
                .HasMaxLength(400)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.EntranceType)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.Key)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.RegistUserId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");

            entity.HasOne(d => d.RegistUser).WithMany(p => p.ThirdPartyEntrances)
                .HasForeignKey(d => d.RegistUserId)
                .HasConstraintName("FK__ThirdPart__Regis__01D345B0");
        });

        modelBuilder.Entity<UserDetail>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__UserDeta__3214EC07CD45A886");

            entity.ToTable("UserDetail");

            entity.Property(e => e.Id)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.CreateTime).HasColumnType("datetime");
            entity.Property(e => e.Key)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.RegistUserId)
                .HasMaxLength(200)
                .IsUnicode(false);
            entity.Property(e => e.UpdateTime).HasColumnType("datetime");
            entity.Property(e => e.Value)
                .HasMaxLength(400)
                .IsUnicode(false);

            entity.HasOne(d => d.RegistUser).WithMany(p => p.UserDetails)
                .HasForeignKey(d => d.RegistUserId)
                .HasConstraintName("FK__UserDetai__Regis__7EF6D905");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
